# Maintainer: Oleg Tolmatcev <oleg.tolmatcev@gmail.com>

_realname=qpdf
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=10.1.0
pkgrel=1
pkgdesc="QPDF: A Content-Preserving PDF Transformation System (mingw-w64)"
arch=('any')
url="https://github.com/qpdf/qpdf"
license=('custom:Artistic-2.0' 'Apache')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-libjpeg"
         "${MINGW_PACKAGE_PREFIX}-pcre"
         "${MINGW_PACKAGE_PREFIX}-zlib")
#https://sourceforge.net/projects/${_realname}/files/${_realname}/${pkgver}/${_realname}-${pkgver}.tar.gz
source=(https://github.com/qpdf/qpdf/releases/download/release-${_realname}-${pkgver}/${_realname}-${pkgver}.tar.gz{,.asc}
        "0001-fix-printf-on-mingw-w64.patch"
        "0002-enable-advapi32-mingw.patch"
        "0003-install-rule.patch")
sha512sums=('f9b22d89fc62e430e6232c840ad74d220ac9eb09d7f2dfe2c42c1c943d35b5fd25e2abec9970ac19ad7ad25dc3d95c74e68e50bad395abf815cf71c432233106'
            'SKIP'
            '8d02655546e2e8182b3ac8df0387d4e34d1e86ee44d1311f5349fd8f82a328583785f2c99feee4c65db2569629b76a0b6edeb5b9bbf3b6b01d3708847a1f15bf'
            '485f108e96b92e76620fcf8e3ddc350d67c5458eea0adcd6a5e11d29fa980c7d9672f832aaec644b39f57674fa505a8d5748059a6b0da027be38b1a7ed01036e'
            '4b93c1af24d5afc84445b00563da0ab60d46654830104690e53844dc1bdb278ac39d8a059c12501f34afb31411a53e2b46f3f953e690f582e3561a9eeb9131a5')
validpgpkeys=('C2C96B10011FE009E6D1DF828A75D10998012C7E') # Jay Berkenbilt <ejb@ql.org>

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  #patch -p1 -i "${srcdir}/0001-fix-printf-on-mingw-w64.patch"
  patch -p1 -i "${srcdir}/0002-enable-advapi32-mingw.patch"
  patch -p1 -i "${srcdir}/0003-install-rule.patch"

  ./autogen.sh
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  cp -rf ${_realname}-${pkgver} build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-crypto-gnutls \
    --disable-crypto-openssl \
    --disable-implicit-crypto \
    --disable-test-compare-images \
    --enable-external-libs \
    --with-buildrules=mingw
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
